from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-02 14:04:23.566396
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 02, Jan, 2022
Time: 14:04:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6602
Nobs: 524.000 HQIC: -48.1055
Log likelihood: 6077.03 FPE: 9.62899e-22
AIC: -48.3921 Det(Omega_mle): 8.12252e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.371697 0.076603 4.852 0.000
L1.Burgenland 0.101296 0.043312 2.339 0.019
L1.Kärnten -0.113379 0.022338 -5.076 0.000
L1.Niederösterreich 0.180570 0.089904 2.008 0.045
L1.Oberösterreich 0.104274 0.089674 1.163 0.245
L1.Salzburg 0.276025 0.046363 5.954 0.000
L1.Steiermark 0.026477 0.060149 0.440 0.660
L1.Tirol 0.108822 0.048600 2.239 0.025
L1.Vorarlberg -0.077251 0.042824 -1.804 0.071
L1.Wien 0.027350 0.080769 0.339 0.735
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.038118 0.168539 0.226 0.821
L1.Burgenland -0.043376 0.095293 -0.455 0.649
L1.Kärnten 0.037774 0.049146 0.769 0.442
L1.Niederösterreich -0.212770 0.197802 -1.076 0.282
L1.Oberösterreich 0.456360 0.197298 2.313 0.021
L1.Salzburg 0.300931 0.102005 2.950 0.003
L1.Steiermark 0.112975 0.132337 0.854 0.393
L1.Tirol 0.312019 0.106927 2.918 0.004
L1.Vorarlberg 0.016990 0.094219 0.180 0.857
L1.Wien -0.009489 0.177703 -0.053 0.957
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215819 0.039018 5.531 0.000
L1.Burgenland 0.093468 0.022061 4.237 0.000
L1.Kärnten -0.005560 0.011378 -0.489 0.625
L1.Niederösterreich 0.227250 0.045793 4.963 0.000
L1.Oberösterreich 0.160260 0.045676 3.509 0.000
L1.Salzburg 0.037745 0.023615 1.598 0.110
L1.Steiermark 0.029206 0.030637 0.953 0.340
L1.Tirol 0.078688 0.024755 3.179 0.001
L1.Vorarlberg 0.055036 0.021813 2.523 0.012
L1.Wien 0.109285 0.041140 2.656 0.008
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150816 0.039000 3.867 0.000
L1.Burgenland 0.040640 0.022051 1.843 0.065
L1.Kärnten -0.013051 0.011372 -1.148 0.251
L1.Niederösterreich 0.161223 0.045771 3.522 0.000
L1.Oberösterreich 0.333641 0.045654 7.308 0.000
L1.Salzburg 0.101870 0.023604 4.316 0.000
L1.Steiermark 0.111546 0.030622 3.643 0.000
L1.Tirol 0.089985 0.024743 3.637 0.000
L1.Vorarlberg 0.054102 0.021802 2.482 0.013
L1.Wien -0.031664 0.041120 -0.770 0.441
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125513 0.073350 1.711 0.087
L1.Burgenland -0.039845 0.041472 -0.961 0.337
L1.Kärnten -0.039676 0.021389 -1.855 0.064
L1.Niederösterreich 0.137502 0.086085 1.597 0.110
L1.Oberösterreich 0.170510 0.085865 1.986 0.047
L1.Salzburg 0.270976 0.044394 6.104 0.000
L1.Steiermark 0.073622 0.057594 1.278 0.201
L1.Tirol 0.138883 0.046536 2.984 0.003
L1.Vorarlberg 0.096719 0.041005 2.359 0.018
L1.Wien 0.069315 0.077338 0.896 0.370
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.088659 0.057723 1.536 0.125
L1.Burgenland 0.019356 0.032637 0.593 0.553
L1.Kärnten 0.052187 0.016832 3.100 0.002
L1.Niederösterreich 0.181059 0.067745 2.673 0.008
L1.Oberösterreich 0.326927 0.067573 4.838 0.000
L1.Salzburg 0.045447 0.034936 1.301 0.193
L1.Steiermark -0.001167 0.045324 -0.026 0.979
L1.Tirol 0.125424 0.036622 3.425 0.001
L1.Vorarlberg 0.062536 0.032269 1.938 0.053
L1.Wien 0.100677 0.060862 1.654 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163081 0.069982 2.330 0.020
L1.Burgenland 0.010053 0.039568 0.254 0.799
L1.Kärnten -0.062664 0.020407 -3.071 0.002
L1.Niederösterreich -0.110190 0.082133 -1.342 0.180
L1.Oberösterreich 0.220733 0.081924 2.694 0.007
L1.Salzburg 0.046278 0.042356 1.093 0.275
L1.Steiermark 0.259107 0.054950 4.715 0.000
L1.Tirol 0.491244 0.044399 11.064 0.000
L1.Vorarlberg 0.065825 0.039122 1.683 0.092
L1.Wien -0.079774 0.073787 -1.081 0.280
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150514 0.077489 1.942 0.052
L1.Burgenland -0.008265 0.043813 -0.189 0.850
L1.Kärnten 0.064441 0.022596 2.852 0.004
L1.Niederösterreich 0.171421 0.090944 1.885 0.059
L1.Oberösterreich -0.071740 0.090712 -0.791 0.429
L1.Salzburg 0.215052 0.046899 4.585 0.000
L1.Steiermark 0.142331 0.060845 2.339 0.019
L1.Tirol 0.051428 0.049162 1.046 0.296
L1.Vorarlberg 0.145414 0.043319 3.357 0.001
L1.Wien 0.142100 0.081703 1.739 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.452890 0.043980 10.298 0.000
L1.Burgenland -0.002290 0.024866 -0.092 0.927
L1.Kärnten -0.015998 0.012824 -1.247 0.212
L1.Niederösterreich 0.186613 0.051615 3.615 0.000
L1.Oberösterreich 0.229517 0.051484 4.458 0.000
L1.Salzburg 0.028477 0.026618 1.070 0.285
L1.Steiermark -0.012093 0.034533 -0.350 0.726
L1.Tirol 0.078892 0.027902 2.827 0.005
L1.Vorarlberg 0.050441 0.024586 2.052 0.040
L1.Wien 0.006294 0.046371 0.136 0.892
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.031064 0.091746 0.158736 0.138869 0.073898 0.078092 0.014846 0.208668
Kärnten 0.031064 1.000000 -0.029803 0.132476 0.046896 0.078595 0.450599 -0.075036 0.095119
Niederösterreich 0.091746 -0.029803 1.000000 0.296168 0.109673 0.256287 0.052755 0.146491 0.258584
Oberösterreich 0.158736 0.132476 0.296168 1.000000 0.203696 0.285490 0.159729 0.128828 0.206522
Salzburg 0.138869 0.046896 0.109673 0.203696 1.000000 0.117410 0.067428 0.103825 0.088957
Steiermark 0.073898 0.078595 0.256287 0.285490 0.117410 1.000000 0.128147 0.093960 0.008444
Tirol 0.078092 0.450599 0.052755 0.159729 0.067428 0.128147 1.000000 0.057867 0.136403
Vorarlberg 0.014846 -0.075036 0.146491 0.128828 0.103825 0.093960 0.057867 1.000000 -0.019048
Wien 0.208668 0.095119 0.258584 0.206522 0.088957 0.008444 0.136403 -0.019048 1.000000